package com.supor.aiot.food.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.android.baseconfig.common.views.RoundImageView;
import com.bumptech.glide.Glide;
import com.supor.aiot.food.R;
import com.supor.aiot.food.bean.ChildList;
import com.supor.aiot.food.bean.ClassifyBean;

import java.util.List;


public class ClassifyTopAdapter extends RecyclerView.Adapter<ClassifyTopAdapter.ClassifyGoodsHolder>{
    private List<ChildList> mList;
    private Context mContext;
    private OnClassifyClickListener recipeDeviceClick;
    public ClassifyTopAdapter(List<ChildList> mList, Context mContext , OnClassifyClickListener listener) {
        this.mList = mList;
        this.mContext = mContext;
        this.recipeDeviceClick = listener;
    }

    @NonNull
    @Override
    public ClassifyTopAdapter.ClassifyGoodsHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view= LayoutInflater.from(mContext).inflate(R.layout.item_classify_top,parent, false);
        return new ClassifyTopAdapter.ClassifyGoodsHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ClassifyGoodsHolder holder, int position) {
        ChildList childList = mList.get(position);
        holder.llGoodsOuter.setOnClickListener(view -> recipeDeviceClick.OnClassifyClick(position));
        if (!TextUtils.isEmpty(childList.getClassificationName()))holder.tvGoodsName.setText(childList.getClassificationName());
        if (!TextUtils.isEmpty(childList.getClassificationImage()))Glide.with(mContext).load(childList.getClassificationImage()).into(holder.ivGoodsImg);
    }


    @Override
    public int getItemCount() {
        return mList.size();
    }

    public class ClassifyGoodsHolder extends RecyclerView.ViewHolder{
        private RoundImageView ivGoodsImg;
        private RelativeLayout llGoodsOuter;
        private TextView tvGoodsName;
        public ClassifyGoodsHolder(@NonNull View itemView) {
            super(itemView);
            ivGoodsImg=itemView.findViewById(R.id.iv_top_img);
            llGoodsOuter=itemView.findViewById(R.id.ll_top_outer);
            tvGoodsName=itemView.findViewById(R.id.tv_top_name);
        }
    }

    public interface OnClassifyClickListener {
        void OnClassifyClick(int position);
    }

}
